package cn.sc.allinpay.allfavour.business.login;

import android.os.Bundle;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatTextView;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;

/**
 * 登录
 */
public class LoginActivity extends BaseActivity<LoginContract.View, LoginContract.Presenter> implements LoginContract.View {

    @BindView(R.id.etName)
    AppCompatEditText etName;
    @BindView(R.id.etPwd)
    AppCompatEditText etPwd;

    @Override
    protected int layoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("登录");
        right.setText("设置");
        right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                presenter.goSetConfig();
            }
        });
    }

    @Override
    protected LoginContract.Presenter bindPresenter() {
        return new LoginPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {
        final InputMethodManager manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        etPwd.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    presenter.callSign();
                }
                return false;
            }
        });
    }

    @Override
    public String getUserName() {
        return etName.getText().toString().trim();
    }

    @Override
    public String getPassword() {
        return etPwd.getText().toString().trim();
    }


    @OnClick(R.id.btnSign)
    void clickSign() {
        presenter.callSign();
    }
}

